package com.example.maybeaccount;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.maybeaccount.R;

public class CreateAccountDialog extends Dialog {

    private Context context;

    /**
     * 自定义Dialog监听器
     */

    public interface PriorityListener {

        /**
         * 回调函数，用于在Dialog的监听事件触发后刷新Activity的UI显示
         */


        void setAccountData(String name,String category,String amount,String remark);

    }

    private PriorityListener listener;

    public CreateAccountDialog (Context context,int theme,PriorityListener listener){
        super(context, theme);
        this.context = context;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        LayoutInflater inflate = LayoutInflater.from(context);

        View view = inflate.inflate(R.layout.create_account, null);

        setContentView(view);

        Button button_account_save = (Button) view.findViewById(R.id.button_account_save);
        Button butBack = (Button) findViewById(R.id.button_account_back);
        final EditText accountname = (EditText) view.findViewById(R.id.edit_accountname);
        final EditText accountcategory = (EditText) view.findViewById(R.id.edit_accountcategory);
        final EditText accountmoney = (EditText) view.findViewById(R.id.edit_accountmoney);
        final EditText accountremark = (EditText) view.findViewById(R.id.edit_accountremark);


        button_account_save.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {
                String input1 = accountname.getText().toString();
                String input2 = accountcategory.getText().toString();
                String input3 = accountmoney.getText().toString();
                String input4 = accountremark.getText().toString();
                listener.setAccountData(input1,input2,input3,input4);
                dismiss();

            }

        });

        butBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });


    }

}